﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{
    public static UIController instance;
    public List<GameObject> btnList = new List<GameObject>();
    private Dictionary<string, GameObject> dic = new Dictionary<string, GameObject>();

    private void Awake()
    {
        instance = this;
        for (int i = 0; i < btnList.Count; i++)
        {
            if (dic.ContainsKey(btnList[i].name))
            {
                dic[btnList[i].name] = btnList[i];
            }
            else
            {
                dic.Add(btnList[i].name, btnList[i]);
            }
        }
    }

    public GameObject Get(string name)
    {
        if (!dic.ContainsKey(name))
        {
            return null;
        }

        return dic[name];
    }
#if UNITY_EDITOR

    [ContextMenu("添加到对应的上面")]
    public void AppendToChild()
    {
        var trans = GetComponentsInChildren<Transform>();
        btnList.Clear();


        foreach (var VARIABLE in trans)
        {
            btnList.Add(VARIABLE.gameObject);
        }
    }
#endif

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            Get("Panel").SetActive(true);
        }

        if (Input.GetKeyUp(KeyCode.Escape))
        {
            var data = Get("ShuangseQiu").GetComponent<ShaProList>().envCurData;
//            LoopInstance.Instance.NewPanel("statisticalPanel").GetComponent<statisticalList>()
//                .SetData(data, ModeType.ShuangSeQiu);
        }

        if (Input.GetKeyUp(KeyCode.Q))
        {
//            Get("ShaHaoPanel").GetComponent<LoopCtrl>().SetData();
            LoopInstance.Instance.NewPanel("ShaHaoPanel");
        }
    }

//    public 
}